# Replication archive for: Coppock, Alexander and Seth J. Hill and Lynn Vavreck. 2020. "The Small Effects of Political Advertising are Small Regardless of Context, Message, Sender, or Receiver: Evidence from 59 Real-time Randomized Experiments" Science Advances, forthcoming.

library(tidyverse)
library(estimatr)
library(metafor)
library(texreg)
source("helpers.R")

favorability_cates <- read_rds("favorability_cates.rds")
vote_choice_cates <- read_rds("vote_choice_cates.rds")

# big meta regression -----------------------------------------------------

fit_1 <- rma.uni(
  yi = estimate,
  sei = std.error,
  mods = ~ date_d + general_d + attack_d +
    democrat_d + independent_d + battleground_d + pac_d,
  data = favorability_cates
)

fit_2 <- rma.uni(
  yi = estimate,
  sei = std.error,
  mods = ~  date_d +
    pro_sanders_d + pro_trump_d + pro_cruz_d + pro_kasich_d + anti_clinton_d + anti_trump_d +
    democrat_d + independent_d + battleground_d + pac_d,
  data = favorability_cates
)

fit_3 <- rma.uni(
  yi = estimate,
  sei = std.error,
  mods = ~ date_d + attack_d +
    democrat_d + independent_d + battleground_d + pac_d,
  data = vote_choice_cates
)

fit_4 <- rma.uni(
  yi = estimate,
  sei = std.error,
  mods = ~  date_d +
    pro_trump_d + anti_clinton_d + anti_trump_d +
    democrat_d + independent_d + battleground_d++pac_d,
  data = vote_choice_cates
)

# These lm models are here to trick texreg --------------------------------

fit_1_lm <- lm(
  estimate ~ date_d + general_d + attack_d +
    democrat_d + independent_d + battleground_d + pac_d,
  data = favorability_cates
)

fit_2_lm <- lm(
  estimate ~  date_d +
    pro_sanders_d + pro_trump_d + pro_cruz_d + pro_kasich_d + anti_clinton_d + anti_trump_d +
    democrat_d + independent_d + battleground_d + pac_d,
  data = favorability_cates
)

fit_3_lm <- lm(estimate ~ date_d + attack_d +
                 democrat_d + independent_d + battleground_d + pac_d,
               data = vote_choice_cates)

fit_4_lm <- lm(
  estimate ~  date_d +
    pro_trump_d + anti_clinton_d + anti_trump_d +
    democrat_d + independent_d + battleground_d + pac_d,
  data = vote_choice_cates
)

fitlist_lm <- list(fit_1_lm, fit_2_lm, fit_3_lm, fit_4_lm)
fitlist <- list(fit_1, fit_2, fit_3, fit_4)

texreg(
  l = fitlist_lm,
  override.coef = texprep(fitlist, stat = "estimate"),
  override.se = texprep(fitlist, stat = "se"),
  override.pvalues = texprep(fitlist, stat = "pval"),
  stars = 0.05,
  include.rsq = FALSE,
  include.adjrs = FALSE,
  include.rmse = FALSE,
  digits = 3,
  custom.coef.names = c(
    "Average effect",
    "Time (scaled in months)",
    "General election (vs. primary election)",
    "Attack ad (vs. promotional ad)",
    "Democratic respondent (vs. Republican)",
    "Independent respondent (vs. Republican)",
    "Battleground state (vs. nonbattleground)",
    "PAC sponsor (vs. campaign sponsor)",
    "Pro Sanders Ad (vs. Pro Clinton ad)",
    "Pro Trump Ad (vs. Pro Clinton ad)",
    "Pro Cruz Ad (vs. Pro Clinton ad)",
    "Pro Kasich Ad (vs. Pro Clinton ad)",
    "Anti Clinton Ad (vs. Pro Clinton ad)",
    "Anti Trump Ad (vs. Pro Clinton ad)"
  ),
  reorder.coef = c(1, 5, 6, 7, 8, 2, 4, 3,
                   10, 13, 14, 9, 11, 12)
)
#\multicolumn{6}{p{.9\linewidth}}
